package com.lagou.task17;

import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;

public class FileReaderTest {
    public static void main(String[] args) {
        FileReader  fr1 = null;
        try {
            //1.构造FileReader类型对象与文件关联
            fr1 = new FileReader("./a.txt");
/*            int res = 1;
            while (-1 != res){
                //读取数据
                res = fr1.read();
                System.out.println((char)res);
            }*/
            //准备一个字符数组用来保存读取到的数据

//            char[] chars1 = new char[20];
//            fr1.read(chars1);
//            System.out.println(Arrays.toString(chars1));

            char[] chars = new char[5];
            fr1.read(chars,1,3);
            System.out.println(Arrays.toString(chars));
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (null != fr1) {
            //关闭流对象
            try {
                fr1.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
